package com.zhufeng.jvm.classloader;

import java.sql.Driver;
import java.util.Iterator;
import java.util.ServiceLoader;


public class MyTest25 {

	public static void main(String[] args) {
		
		// 加上这行代码ServiceLoader就加载不了Driver驱动
		Thread.currentThread().setContextClassLoader(MyTest25.class.getClassLoader().getParent());
		
		ServiceLoader<Driver> serviceLoader = ServiceLoader.load(Driver.class);
		Iterator<Driver> it = serviceLoader.iterator();
		
		while(it.hasNext()) {
			Driver driver = it.next();
			System.out.println("driver: " + driver.getClass() + ", classLoader: " + driver.getClass().getClassLoader());
			
		}
		
		System.out.println("当前上下文类加载器：" + Thread.currentThread().getContextClassLoader());
		
		System.out.println("ServiceLoader的类加载器：" + ServiceLoader.class.getClassLoader());
	}
}
